//
//  LSExpertsCollectionViewCell.m
//  LookScore
//
//  Created by wr on 2018/5/17.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSExpertsCollectionViewCell.h"
#import "LSExpertRankModel.h"
@implementation LSExpertsCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeInterface];
    }
    return self;
}
- (void)initializeInterface{
    [self.contentView addSubview:self.headImageView];
    [self.contentView addSubview:self.ExpertName];
    [self.contentView addSubview:self.followBtn];
    
    self.headImageView.sd_layout
    .centerXEqualToView(self.contentView)
    .topEqualToView(self.contentView).offset(LSAutoVlaue(10, LSScreenHeight))
    .widthIs(LSAutoVlaue(50, LSScreenWidth))
    .heightIs(LSAutoVlaue(50, LSScreenHeight));
    
    self.ExpertName.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .topSpaceToView(self.headImageView, LSAutoVlaue(5, LSScreenWidth))
    .autoHeightRatio(0);
    
    self.followBtn.sd_layout
    .leftEqualToView(self.headImageView)
    .rightEqualToView(self.headImageView)
    .topSpaceToView(self.ExpertName, LSAutoVlaue(5, LSScreenWidth))
    .heightIs(LSAutoVlaue(20, LSScreenWidth));
}
- (void)layoutSubviews{
    [super layoutSubviews];
    
}

- (void)clickFollowBtn:(UIButton *)sender{
    sender.selected=!sender.selected;
    if (self.clickFollowButtonBlock) {
        self.clickFollowButtonBlock(self.model.UserCid);
    }
}
- (void)setModel:(LSRecommendListModel *)model{
    _model = model;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    
    self.ExpertName.text = model.UserDisName;
    if (model.IsAttended) {
        self.followBtn.selected = YES;
    }else{
        self.followBtn.selected = NO;
    }
    
}
#pragma mark -- Getter


- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [[UIImageView alloc] init];
        _headImageView.image = [UIImage imageNamed:@"HeadImage"];
    }
    return _headImageView;
}

- (UILabel *)ExpertName{
    if (!_ExpertName) {
        _ExpertName = [[UILabel alloc] init];
//        _ExpertName.backgroundColor = [UIColor redColor];
//        _ExpertName.text = @"足彩分析师";
        _ExpertName.textAlignment = NSTextAlignmentCenter;
        _ExpertName.font = LSFontSize(15,LSScreenWidth);
        _ExpertName.textColor = LSSubColor5D5D5D;
    }
    return _ExpertName;
}


- (UIButton *)followBtn{
    if (!_followBtn) {
        _followBtn = [[UIButton alloc] init];
        [_followBtn setImage:[UIImage imageNamed:@"Follow"] forState:UIControlStateNormal];
        [_followBtn setImage:[UIImage imageNamed:@"Followed"] forState:UIControlStateSelected];
        [_followBtn addTarget:self action:@selector(clickFollowBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _followBtn;
}

@end
